import javax.security.auth.login.CredentialException;
import java.util.Arrays;

public class SzZy {
    public static int duoS(int[] array) {
        Arrays.sort(array);
        return array[array.length/2];
    }

    public static void main(String[] args) {
        int[] array = {2,2,1,1,1,2,2};
        int ret = duoS(array);
        System.out.println(ret);
    }

    public static int one(int[] array) {
        int ret = array[0];
        for (int i = 1; i < array.length; i++) {
            ret ^= array[i];
        }
        return ret;
    }

    public static void main5(String[] args) {
        int[] array = {1,2,2};
        int ret = one(array);
        System.out.println(ret);
    }

    public static int[] num(int[] array,int k) {
        int[] ret = {-1,-1};
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length; j++) {
                if (array[i] + array[j] == k) {
                    ret[0] = i;
                    ret[1] = j;
                    return ret;
                }
            }
        }
        return ret;
    }

    public static void main4(String[] args) {
        int[] array = {2,7,11,15};
        System.out.println(Arrays.toString(num(array,9)));
    }

    public static void maoP(int[] array) {
        for (int i = 0; i < array.length-1; i++) {
            boolean f = false;
            for (int j = 0; j < array.length-1; j++) {
                if (array[j] > array[j+1]) {
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    f = true;
                }
            }
            if (f = false) {
                return;
            }
        }
    }

    public static void main3(String[] args) {
        int[] array = {12,25,4,56,8,96};
        maoP(array);
        System.out.println(Arrays.toString(array));
    }

    public static int binarySearch(int[] array,int k) {
        int left = 0;
        int right = array.length-1;
        while (left <= right) {
            int mid = ((left + right) / 2);
            if (array[mid] < k) {
                left = mid + 1;
            }else if (array[mid] > k) {
                right = mid - 1;
            }else {
                return mid;
            }
        }
        return -1;
    }
    public static void main2(String[] args) {
        //二分查找
        int[] array = {11,2,3,4,5,6};
        Arrays.sort(array);//排序
        System.out.println(binarySearch(array, 11));
        //库方法
        //System.out.println(Arrays.binarySearch(array, 11));

    }

    public static int findNum(int[] array,int k) {
        int left = 0;
        int right = array.length-1;
        while (left <= right) {
            int middle = (left+right)/2;
            if (array[middle] < k) {
                left = middle + 1;
            }else if (array[middle] > k) {
                right = middle - 1;
            }else {
                return middle;
            }
        }
        return -1;
    }

    public static void main1(String[] args) {
        int[] array = {11,22,33,44,55,66};
        System.out.println(findNum(array,66));
    }
}
